package com.txts.road.admin.stageSys.controller;

import com.txts.base.common.domain.PageResult;
import com.txts.base.common.domain.ResponseDTO;
import com.txts.road.admin.common.annotation.Anonymous;
import com.txts.road.admin.common.annotation.Log;
import com.txts.road.admin.common.core.controller.BaseController;
import com.txts.road.admin.common.core.domain.AjaxResult;
import com.txts.road.admin.common.core.page.TableDataInfo;
import com.txts.road.admin.common.enums.BusinessType;
import com.txts.road.admin.common.utils.poi.ExcelUtil;
import com.txts.road.admin.stageSys.domain.StageRankings;
import com.txts.road.admin.stageSys.service.IStageRankingsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;

import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 赛段排名Controller
 *
 * @author ruoyi
 * @date 2025-05-16
 */
@RestController
@RequestMapping("/stageSys/stageInfo")
@Tag(name = "赛段排名接口")
public class StageRankingsController extends BaseController {
    @Resource
    private IStageRankingsService stageRankingsService;

    /**
     * 查询赛段排名列表
     */
    @Anonymous
    @GetMapping("/list")
    @Operation(summary = "查询赛段排名列表", description = "根据条件查询赛段排名列表")
    public ResponseDTO<PageResult<StageRankings>> list(StageRankings stageRankings) {
        startPage();
        List<StageRankings> list = stageRankingsService.selectStageRankingsList(stageRankings);
        return getDataTable(list);
    }

    /**
     * 导出赛段排名列表
     */
    @PreAuthorize("@ss.hasPermi('stageSys:stageInfo:export')")
    @Log(title = "赛段排名", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @Operation(summary = "导出赛段排名列表", description = "导出赛段排名列表")
    public void export(HttpServletResponse response, StageRankings stageRankings) {
        List<StageRankings> list = stageRankingsService.selectStageRankingsList(stageRankings);
        ExcelUtil<StageRankings> util = new ExcelUtil<StageRankings>(StageRankings.class);
        util.exportExcel(response, list, "赛段排名数据");
    }

    /**
     * 获取赛段排名详细信息
     */
    @PreAuthorize("@ss.hasPermi('stageSys:stageInfo:query')")
    @GetMapping(value = "/{id}")
    @Operation(summary = "获取赛段排名详细信息", description = "根据ID获取赛段排名详细信息")
     public ResponseDTO<Object> getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(stageRankingsService.selectStageRankingsById(id));
    }

    /**
     * 新增赛段排名
     */
    @PreAuthorize("@ss.hasPermi('stageSys:stageInfo:add')")
    @Log(title = "赛段排名", businessType = BusinessType.INSERT)
    @PostMapping
    @Operation(summary = "新增赛段排名", description = "新增赛段排名")
    public ResponseDTO<Object>add(@RequestBody StageRankings stageRankings) {
        return toAjax(stageRankingsService.insertStageRankings(stageRankings));
    }

    /**
     * 修改赛段排名
     */
    @PreAuthorize("@ss.hasPermi('stageSys:stageInfo:edit')")
    @Log(title = "赛段排名", businessType = BusinessType.UPDATE)
    @PutMapping
    @Operation(summary = "修改赛段排名", description = "修改赛段排名")
    public ResponseDTO<Object>edit(@RequestBody StageRankings stageRankings) {
        return toAjax(stageRankingsService.updateStageRankings(stageRankings));
    }

    /**
     * 删除赛段排名
     */
    @PreAuthorize("@ss.hasPermi('stageSys:stageInfo:remove')")
    @Log(title = "赛段排名", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @Operation(summary = "删除赛段排名", description = "删除赛段排名")
    public ResponseDTO<Object>remove(@PathVariable String[] ids) {
        return toAjax(stageRankingsService.deleteStageRankingsByIds(ids));
    }


    @GetMapping("/listAllSaiduan")
    @Operation(summary = "查询所有赛段", description = "查询所有赛段列表")
     public ResponseDTO<Object> listAllSaiduan() {
        return AjaxResult.success(stageRankingsService.selectAllSaiduan());
    }

    @GetMapping("/listAllSaiche")
     public ResponseDTO<Object> listAllSaiche() {
        return AjaxResult.success(stageRankingsService.selectAllSaiche());
    }

    @GetMapping("/listAllSaicheshou")
     public ResponseDTO<Object> listAllSaicheshou(@RequestParam(required = false) String saiche) {
        return AjaxResult.success(stageRankingsService.selectAllSaicheshou(saiche));
    }
}
